package org.smart4j.framework.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * Created by Lin on 2018/04/16.
 */
public final class CodecUtil {
    private static final Logger logger = LoggerFactory.getLogger(CodecUtil.class);

    public static String encodeURL(String url){
        String target;
        try {
            target = URLEncoder.encode(url, "utf-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("encode failure", e);
            throw new RuntimeException(e);
        }
        return target;

    }

    public static String decodeURL(String url) {
        String target;
        try {
            target = URLDecoder.decode(url, "utf-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("decode failure", e);
            throw new RuntimeException(e);
        }
        return target;
    }
}
